<?php

namespace App\View\Components;

use Illuminate\View\Component;
use PhpParser\Node\Scalar\String_;

class Dropdown extends Component
{
    public string $title;
    public array $options;
    public int $selectedItem;
    public int $index;

    /**
     * Create a new component instance.
     *
     * @return void
     */
    public function __construct(string $title, array $options = [], int $selectedItem = 0, int $index = 0)
    {
        $this->title = $title;
        $this->options = $options;
        $this->selectedItem = session($title) ?: $selectedItem;
        $this->index = $index;
    }

    public function getSelectedItem()
    {
        return $this->selectedItem;
    }

    /**
     * @param int $selectedItem
     */
    public function setSelectedItem(int $selectedItem): void
    {
        session()->put($this->title, $selectedItem);
        $this->selectedItem = $selectedItem;
    }

    public function addIndex(): void
    {
        $this->index++;
        var_dump($this->index);
    }


    /**
     * Get the view / contents that represent the component.
     *
     * @return \Illuminate\Contracts\View\View|\Closure|string
     */
    public function render()
    {
        return view('components.dropdown');
    }
}
